import u from "../utils";
import { DATASET } from "../constants";

const _api = u.api(DATASET);

export const loadDataSource = () => _api('dataSource', { data: {}, type: 'get' });
export const currentDataSouece = (id = 'default') => _api(`dataSource/${id}`, { data: {}, type: 'get' });
export const loadTables = (dsName) => _api('listTableOrView', { data: { dsName }, type: 'get' });

export const getTableFields = (dsName, tableName) => _api('tableFields', { data: { dsName, tableName }, type: 'get' });

export const saveDataSet = ({ id = '', ...params }) => _api(`dataSet${id ? '/' : ''}${id}`, { data: params, type: 'post' });
export const getDataSet = (uuid = '') => _api(`dataSet${uuid ? '/' : ''}${uuid}`, { data: {}, type: 'get' });

export const loadPageDs = (pageid) => _api(`pageDs`, { data: { pageid }, type: 'get' });

export const listDataSetTableFields = id => _api(`fields/${id}`, { data: {}, type: 'get' });

export const nativeFields = pageid => _api('nativeFields', { data: { pageid }, type: 'get' });

export const loadCondition = id => _api(`condition/${id}`, { type: 'get', data: {} });

export const getDataCondition = id => _api(`getDataCondition/${id}`, { type: 'get', data: {} });

export const loadPageFieldAssign = (pageid) => _api(`getPageFieldAssign`, { type: 'get', data: { pageid } });

export const saveFieldAssign = ({ id = '', ...params }) => _api(`saveFieldAssign${id ? '/' : ''}${id}`, { data: params, type: 'post' });

export const getFieldAssign = (id = '') => _api(`getFieldAssign${id ? '/' : ''}${id}`, { data: {}, type: 'get' });

export const deleteFieldAssign = id => _api(`deleteFieldAssign/${id}`, { type: 'get', data: {} });

export const deleteDataSet = id => _api(`deleteDataSet/${id}`, { type: 'get', data: {} });
